home *** CD-ROM | disk | FTP | other *** search
- /*
- * (c) Copyright 1992 by Panagiotis Tsirigotis
- * All rights reserved. The file named COPYRIGHT specifies the terms
- * and conditions for redistribution.
- */
-
- static char RCSid[] = "$Id: servtab.c,v 5.2 1992/11/10 08:18:25 panos Exp $" ;
-
- #include <syslog.h>
-
- #include "pset.h"
- #include "sio.h"
-
- #include "service.h"
- #include "state.h"
-
- void msg() ;
- void out_of_memory() ;
-
-
- /*
- * Try to start all services in the specified service table.
- * On exit, all services in that table that were activated will
- * be in state SVC_ACTIVE.
- */
- unsigned start_services( services )
- pset_h services ;
- {
- psi_h iter ;
- unsigned services_started = 0 ;
- register struct service *sp ;
- char *func = "start_services" ;
-
- iter = psi_create( services ) ;
- if ( iter == NULL )
- {
- out_of_memory( func ) ;
- return( 0 ) ;
- }
-
- for ( sp = SP( psi_start( iter ) ) ; sp ; sp = SP( psi_next( iter ) ) )
- {
- /*
- * We only start inactive services
- */
- if ( sp->state != SVC_NOT_STARTED )
- continue ;
-
- if ( svc_activate( sp ) == FAILED )
- {
- svc_deactivate( sp ) ;
- continue ;
- }
-
- /*
- * descriptors_free can be negative without a descriptor-allocating
- * system call failing because some of the descriptors we reserve
- * are transient
- */
- if ( ps.rws.descriptors_free < 0 )
- {
- msg( LOG_ERR, func,
- "Service %s disabled because of lack of file descriptors",
- CONF( sp )->id ) ;
- svc_deactivate( sp ) ;
- continue ;
- }
-
- /*
- * Activation successful; add service to service table
- */
- if ( pset_add( SERVICES( ps ), sp ) == NULL )
- {
- out_of_memory( func ) ;
- svc_deactivate( sp ) ;
- continue ;
- }
-
- SVC_HOLD( sp ) ;
-
- services_started++ ;
-
- if ( debug.on )
- msg( LOG_DEBUG, func, "Started service: %s", CONF( sp )->id ) ;
- }
-
- psi_destroy( iter ) ;
-
- if ( debug.on )
- msg( LOG_DEBUG, func, "mask_max = %d, services_started = %d",
- ps.rws.mask_max, services_started ) ;
-
- return( services_started ) ;
- }
-
-
-
- void destroy_services( stab )
- pset_h stab ;
- {
- register unsigned u ;
-
- for ( u = 0 ; u < pset_count( stab ) ; u++ )
- svc_free( SP( pset_pointer( stab, u ) ) ) ;
- pset_destroy( stab ) ;
- }
-
-
-
- void list_services( stab, fd )
- pset_h stab ;
- int fd ;
- {
- register unsigned u ;
-
- for ( u = 0 ; u < pset_count( stab ) ; u++ )
- {
- svc_dump( SP( pset_pointer( stab, u ) ), fd ) ;
- Sputchar( fd, '\n' ) ;
- }
- }
-
-